﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Media.Imaging;
using Tulde.Windows.Music.ViewModel;
using Tulde.Windows.Music.Mp3Tunes;

namespace MP3Tunes.WPF
{
    public static class AlbumArtResource
    {
        public static BitmapImage Load(string url)
        {
            if (String.IsNullOrEmpty(url))
            {
                BitmapImage logo = new BitmapImage();
                return logo;
            }
            else
            {
                BitmapImage logo = new BitmapImage();
                logo.BeginInit();
                logo.UriSource = new Uri(url);
                logo.EndInit();
                return logo;
            }
        }
        public static BitmapImage Load(Album album, AlbumArtSizeOptions size = AlbumArtSizeOptions.medium)
        {
            AlbumArtService service = new AlbumArtService();
            Uri url = service.CreateServiceEndpoint(LockerDataOperations.albumartget, new AlbumArtServiceParameters
            {
                AlbumServiceKey = album.AlbumId,
                Size = size
            });

            try
            {
                BitmapImage logo = new BitmapImage();
                logo.BeginInit();
                logo.UriSource = url;
                logo.EndInit();
                return logo;
            }
            catch
            {
                return new BitmapImage();
            }
        }
    }
}
